"use strict";
/**
 * @ Author: Yoann Meclot. MSay2
 * @ Created on: 2020-08-29 07:59:03
 * @ Modified on: 2021-06-17 14:03:37
 */
/**
 * Copyright (c) 2020-2021 MSay2 (Yoann Meclot) - @msay2/tspoet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.CodeWriter = void 0;
const Exceptions_js_1 = require("../util/Exceptions.js");
const Arrays_js_1 = require("../util/list/Arrays.js");
const LinkedMap_js_1 = require("../util/list/LinkedMap.js");
const Objects_js_1 = require("../util/Objects.js");
const StringBuilder_js_1 = require("../util/StringBuilder.js");
const Utils_js_1 = require("../util/Utils.js");
const Modifier_js_1 = require("./Modifier.js");
const ObjectName_js_1 = require("./ObjectName.js");
const TSAnnotation_js_1 = require("./TSAnnotation.js");
const TSField_js_1 = require("./TSField.js");
const TSPoet_js_1 = require("./TSPoet.js");
class CodeWriter {
    constructor(mIndents) {
        this.mAppendable = new StringBuilder_js_1.StringBuilder();
        this.mIndents = 0;
        if (!Objects_js_1.Objects.isNull(mIndents))
            this.mIndents = mIndents;
    }
    emitImports(ownerName, list) {
        let builder = new StringBuilder_js_1.StringBuilder();
        for (let entry of list.entries()) {
            let objectName = entry.getValue();
            if (ownerName != objectName.asType().getName() && !Utils_js_1.UString.isEmpty(objectName.asImport().getPath())) {
                let path = objectName.asImport().getPath();
                let name = objectName.asType().getName();
                builder.append(`import { ${name} } from "${path}/${name}.js"`)
                    .append(CodeWriter.SEMICOLON)
                    .append(CodeWriter.NEW_LINE);
                if (entry.isLastData())
                    builder.append(CodeWriter.NEW_LINE);
            }
        }
        this.mAppendable.appendAt(0, builder.toString());
    }
    emitStartBlock() {
        this.mAppendable.append(CodeWriter.NEW_LINE)
            .append(CodeWriter.BEGIN_BRACE)
            .append(CodeWriter.NEW_LINE);
    }
    emitEndBlock() {
        this.removeAllmIndents();
        this.mAppendable.append(CodeWriter.NEW_LINE)
            .append(CodeWriter.END_BRACE);
    }
    emitKindClass() {
        this.mAppendable.append(TSPoet_js_1.Kind.CLASS);
    }
    emitKindEnum() {
        this.mAppendable.append(TSPoet_js_1.Kind.ENUM);
    }
    emitKindInterface() {
        this.mAppendable.append(TSPoet_js_1.Kind.INTERFACE);
    }
    emitModifiers(modifiers) {
        this.emitModifiersValue(modifiers);
    }
    emitGenericNames(casts) {
        if (!casts.isEmpty()) {
            this.mAppendable.append("<");
            for (let entry of casts.entries())
                this.mAppendable.append(entry.getValue()).append((entry.isLastData() ? "" : ", "));
            this.mAppendable.append(">");
        }
    }
    emitSuperClass(superClass) {
        if (superClass != null && !Utils_js_1.UString.isEmpty(superClass.asType().getName())) {
            this.mAppendable.append(" extends ").append(superClass.asType().getName());
            let listeners = Arrays_js_1.Arrays.asList(superClass.asListener().getListener());
            for (let entry of listeners.entries())
                this.mAppendable.append(".").append(entry.getValue());
            if (!superClass.getCasts().isEmpty()) {
                this.mAppendable.append("<");
                this.emitCast(superClass.getCasts(), this.mAppendable);
                this.mAppendable.append(">");
            }
        }
    }
    emitImplementations(impls) {
        let builder = new StringBuilder_js_1.StringBuilder();
        if (!impls.isEmpty()) {
            for (let entry of impls.entries()) {
                let impl = entry.getValue();
                builder.append(impl.asType().getName());
                let listeners = Arrays_js_1.Arrays.asList(impl.asListener().getListener());
                for (let entry of listeners.entries())
                    builder.append(".").append(entry.getValue());
                if (!impl.getCasts().isEmpty()) {
                    builder.append("<");
                    this.emitCast(impl.getCasts(), builder);
                    builder.append(">");
                }
            }
            this.mAppendable.append(` implements ${builder.toString()}`);
            builder.clear();
        }
    }
    emitMethod(method) {
        let statements = method.mStatments;
        let codeBlocks = method.mCodeBlocks;
        let name = method.mName;
        this.addIndent();
        this.insertIndentation();
        this.emitDocs(method.mDocs);
        this.emitAnnotationValue(method.mAnnotations);
        this.emitModifiersValue(method.mModifiers);
        this.mAppendable.append(name);
        this.emitGenericNames(method.mGenericNames);
        this.emitParameterValue(method.mParameters, this.mAppendable);
        this.emitTypeValue(method.mType);
        this.mAppendable.append(CodeWriter.BEGIN_BRACE);
        if (!statements.isEmpty()) {
            this.mAppendable.append(CodeWriter.NEW_LINE);
            this.addIndent();
            this.insertIndentation();
            for (let entry of statements.entries()) {
                this.mAppendable.append(entry.getValue()).append(entry.isLastData() ? "" : CodeWriter.NEW_LINE);
                if (!entry.isLastData())
                    this.insertIndentation();
            }
        }
        this.emitCodeBlock(codeBlocks, this.mAppendable);
        if (!statements.isEmpty() || !codeBlocks.isEmpty())
            this.mAppendable.append(CodeWriter.NEW_LINE);
        this.removeIndent();
        this.insertIndentation();
        this.mAppendable.append(CodeWriter.END_BRACE);
    }
    emitAbstractMethod(method) {
        this.addIndent();
        this.insertIndentation();
        this.emitDocs(method.mDocs);
        this.emitAnnotationValue(method.mAnnotations);
        this.emitModifiersValue(method.mModifiers);
        this.mAppendable.append(method.mName);
        this.emitGenericNames(method.mGenericNames);
        this.emitParameterValue(method.mParameters, this.mAppendable);
        this.emitTypeValue(method.mType);
        this.mAppendable.append(CodeWriter.SEMICOLON);
    }
    emitField(field) {
        let name = field.mName;
        let value = field.mValue;
        this.addIndent();
        this.insertIndentation();
        this.emitDocs(field.mDocs);
        this.emitAnnotationValue(field.mAnnotations);
        this.emitModifiersValue(field.mModifiers);
        this.mAppendable.append(name);
        this.emitTypeValue(field.mType);
        if (value != undefined) {
            this.mAppendable.append(" = ");
            if ((typeof value) == "object") {
                if (value.constructor.name == "Array") {
                    this.mAppendable.append(CodeWriter.BEGIN_BRACKET);
                    let list = Arrays_js_1.Arrays.asList(value);
                    for (let entry of list.entries())
                        this.emitFieldAnonymousImpls(undefined, entry.getValue(), (!entry.isLastData()), this.mAppendable);
                    this.mAppendable.append(CodeWriter.NEW_LINE);
                    this.insertIndentation();
                    this.mAppendable.append(CodeWriter.END_BRACKET);
                }
                else {
                    this.mAppendable.append(CodeWriter.BEGIN_BRACE);
                    let map = LinkedMap_js_1.LinkedMap.fromObject(value);
                    for (let entry of map.entries())
                        this.emitFieldAnonymousImpls(entry.getKey(), entry.getValue(), (!entry.isLastData()), this.mAppendable);
                    this.mAppendable.append(CodeWriter.NEW_LINE);
                    this.insertIndentation();
                    this.mAppendable.append(CodeWriter.END_BRACE);
                }
            }
            else if (value == TSField_js_1.TSField.UNDEFINED)
                this.mAppendable.append(undefined);
            else if (value.constructor.name == "String")
                this.mAppendable.append(`\`${value}\``);
            else
                this.mAppendable.append(value);
        }
        this.mAppendable.append(CodeWriter.SEMICOLON);
    }
    emitConstant(constant) {
        this.addIndent();
        this.insertIndentation();
        this.emitDocs(constant.mDocs);
        for (let entry of constant.mConstants.entries()) {
            let value = entry.getValue();
            this.mAppendable.append(entry.getKey())
                .append(" = ")
                .append((value.constructor.name == "String" ? `\`${value}\`` : value));
        }
    }
    emitProperty(property) {
        this.addIndent();
        this.insertIndentation();
        this.emitDocs(property.mDocs);
        this.mAppendable.append(property.mName);
        this.emitParameterValue(property.mParameters, this.mAppendable);
        this.emitTypeValue(property.mType);
        this.mAppendable.append(CodeWriter.SEMICOLON);
    }
    emitAnnotation(annotation) {
        let name = annotation.mName;
        let values = annotation.mValues;
        this.mAppendable.append("@").append(name);
        if (!values.isEmpty()) {
            this.mAppendable.append("(");
            for (let entry of values.entries()) {
                let value = entry.getValue();
                if ((typeof value) == "object") {
                    if (value.constructor.name == "Array") {
                        this.mAppendable.append(CodeWriter.BEGIN_BRACKET);
                        let list = Arrays_js_1.Arrays.asList(value);
                        for (let entry of list.entries())
                            this.emitFieldAnonymousImpls(undefined, entry.getValue(), (!entry.isLastData()), this.mAppendable);
                        this.mAppendable.append(CodeWriter.NEW_LINE);
                        this.insertIndentation();
                        this.mAppendable.append(CodeWriter.END_BRACKET);
                    }
                    else if (value instanceof ObjectName_js_1.ObjectName)
                        this.mAppendable.append(value.asType().getName());
                    else {
                        this.mAppendable.append(CodeWriter.BEGIN_BRACE);
                        let map = LinkedMap_js_1.LinkedMap.fromObject(value);
                        for (let entry of map.entries())
                            this.emitFieldAnonymousImpls(entry.getKey(), entry.getValue(), (!entry.isLastData()), this.mAppendable);
                        this.mAppendable.append(CodeWriter.NEW_LINE);
                        this.insertIndentation();
                        this.mAppendable.append(CodeWriter.END_BRACE);
                    }
                }
                else if (value == TSAnnotation_js_1.TSAnnotation.EMPTY_VALUE)
                    this.mAppendable.append("");
                else if (value.constructor.name == "String")
                    this.mAppendable.append(`\`${value}\``);
                else
                    this.mAppendable.append(value);
            }
            this.mAppendable.append(")");
        }
        this.mAppendable.append(CodeWriter.NEW_LINE);
    }
    emitDocs(docs) {
        if (!docs.isEmpty())
            this.emitDocsValue(docs);
    }
    emitComments(comments) {
        for (let entry of comments.entries()) {
            this.insertIndentation();
            this.mAppendable.append("// ").append(entry.getValue()).append(CodeWriter.NEW_LINE);
        }
    }
    emitNestedClass(nestedClasses) {
        for (let entry of nestedClasses.entries()) {
            let type = entry.getValue();
            let modifiers = type.mModifiers;
            let kind = type.mKind;
            let name = type.mObjectName.asType().getName();
            if (kind != TSPoet_js_1.Kind.CLASS)
                throw new Exceptions_js_1.IllegalArgumentException("Nested class cannot have another Kind.");
            let fields = type.mFields;
            let methods = type.mMethods;
            if (entry.isFirstData())
                this.addIndent();
            this.insertIndentation();
            this.emitDocs(type.mDocs);
            for (let entry of type.mComments.entries()) {
                this.mAppendable.append("// ").append(entry.getValue()).append(CodeWriter.NEW_LINE);
                this.insertIndentation();
            }
            this.emitAnnotationValue(type.mAnnotations);
            if (Modifier_js_1.Modifier.isNestedClass(modifiers))
                this.emitModifiersValue(modifiers);
            this.mAppendable.append("static ")
                .append(name)
                .append(" = ")
                .append(TSPoet_js_1.Kind.CLASS)
                .append(" ")
                .append(name);
            this.emitGenericNames(type.mGenericNames);
            this.emitSuperClass(type.mSuperclass);
            this.emitImplementations(type.mImpls);
            this.mAppendable.append(CodeWriter.BEGIN_BRACE).append(CodeWriter.NEW_LINE);
            if (!fields.isEmpty()) {
                for (let entry of fields.entries()) {
                    this.emit(entry.getValue().emit(new CodeWriter(this.mIndents)).toString());
                    this.mAppendable.append(CodeWriter.NEW_LINE);
                }
            }
            if (!methods.isEmpty()) {
                if (!fields.isEmpty())
                    this.mAppendable.append(CodeWriter.NEW_LINE);
                for (let entry of methods.entries()) {
                    this.emit(entry.getValue().emit(new CodeWriter(this.mIndents)).toString());
                    this.mAppendable.append(CodeWriter.NEW_LINE);
                    if (!entry.isLastData())
                        this.mAppendable.append(CodeWriter.NEW_LINE);
                }
            }
            this.insertIndentation();
            this.mAppendable.append(CodeWriter.END_BRACE);
            if (!entry.isLastData())
                this.mAppendable.append(CodeWriter.NEW_LINE).append(CodeWriter.NEW_LINE);
        }
    }
    emitNameSpaceForNestedClass(modifier, owner, nestedClasses) {
        let name = owner.asType().getName();
        this.mAppendable.append(CodeWriter.NEW_LINE)
            .append(CodeWriter.NEW_LINE)
            .append(modifier.getSimpleName())
            .append((modifier.equals(Modifier_js_1.Modifier.UNDEFINED) ? "namespace " : " namespace "))
            .append(name)
            .append(CodeWriter.BEGIN_BRACE);
        for (let entry of nestedClasses.entries()) {
            let type = entry.getValue();
            let typeName = type.mObjectName.asType().getName();
            if (Modifier_js_1.Modifier.isPrivate(type.mModifiers)) {
                if (entry.isFirstData())
                    this.addIndent();
                continue;
            }
            else {
                this.mAppendable.append(CodeWriter.NEW_LINE);
                if (entry.isFirstData())
                    this.addIndent();
            }
            this.insertIndentation();
            for (let entry of type.mComments.entries()) {
                this.mAppendable.append("// ").append(entry.getValue()).append(CodeWriter.NEW_LINE);
                this.insertIndentation();
            }
            this.mAppendable.append("export type ")
                .append(typeName)
                .append(" = InstanceType<typeof ")
                .append(name).append(".").append(typeName)
                .append(">;");
        }
        this.mAppendable.append(CodeWriter.NEW_LINE)
            .append(CodeWriter.END_BRACE);
    }
    emit(arg) {
        this.mAppendable.append(arg);
        return this;
    }
    emitAt(index, arg) {
        this.mAppendable.appendAt(index, arg);
    }
    toString() {
        return this.mAppendable.toString();
    }
    emitCast(list, builder) {
        for (let entry of list.entries()) {
            let type = entry.getValue();
            builder.append(type.asType().getName());
            if (!type.getCasts().isEmpty()) {
                builder.append("<");
                this.emitCast(type.getCasts(), builder);
                builder.append(">");
            }
            if (!entry.isLastData())
                builder.append(", ");
        }
    }
    emitAnnotationValue(annotations) {
        if (!annotations.isEmpty())
            for (let entry of annotations.entries()) {
                this.emitAnnotation(entry.getValue());
                this.insertIndentation();
            }
    }
    emitModifiersValue(modifiers) {
        if (!modifiers.isEmpty())
            for (let entry of modifiers.entries())
                this.mAppendable.append(entry.getValue().getSimpleName()).append(" ");
    }
    emitDocsValue(docs) {
        this.mAppendable.append("/**").append(CodeWriter.NEW_LINE);
        for (let entry of docs.entries()) {
            this.insertIndentation();
            this.mAppendable.append(" * ").append(entry.getValue()).append(CodeWriter.NEW_LINE);
        }
        this.insertIndentation();
        this.mAppendable.append(" */").append(CodeWriter.NEW_LINE);
        this.insertIndentation();
    }
    emitParameterValue(parameters, builder) {
        builder.append("(");
        for (let entry of parameters.entries()) {
            let name = entry.getKey();
            let type = entry.getValue();
            builder.append(name).append(":").append(type.asType().getName());
            let listener = Arrays_js_1.Arrays.asList(type.asListener().getListener());
            if (listener.isEmpty()) {
                if (!type.getCasts().isEmpty()) {
                    builder.append("<");
                    this.emitCast(type.getCasts(), builder);
                    builder.append(">");
                }
            }
            else {
                for (let entry of listener.entries()) {
                    builder.append(".").append(entry.getValue());
                    if (entry.isLastData() && !type.getCasts().isEmpty()) {
                        builder.append("<");
                        this.emitCast(type.getCasts(), builder);
                        builder.append(">");
                    }
                }
            }
            if (!entry.isLastData())
                builder.append(", ");
        }
        builder.append(")");
    }
    emitTypeValue(type) {
        if (type != null) {
            this.mAppendable.append(":").append(type.asType().getName());
            let listener = Arrays_js_1.Arrays.asList(type.asListener().getListener());
            if (listener.isEmpty()) {
                if (!type.getCasts().isEmpty()) {
                    this.mAppendable.append("<");
                    this.emitCast(type.getCasts(), this.mAppendable);
                    this.mAppendable.append(">");
                }
            }
            else {
                for (let entry of listener.entries()) {
                    this.mAppendable.append(".").append(entry.getValue());
                    if (entry.isLastData() && !type.getCasts().isEmpty()) {
                        this.mAppendable.append("<");
                        this.emitCast(type.getCasts(), this.mAppendable);
                        this.mAppendable.append(">");
                    }
                }
            }
        }
    }
    emitCodeBlock(codeBlocks, builder) {
        if (!codeBlocks.isEmpty()) {
            builder.append(CodeWriter.NEW_LINE);
            this.addIndent();
            this.insertIndentation(builder);
            let index = -1;
            for (let entry of codeBlocks.entries()) {
                for (let codes of entry.getValue().mCodes.entries()) {
                    let code = codes.getValue();
                    if (Utils_js_1.UString.contains(code, "{$I}")) {
                        let builder = new StringBuilder_js_1.StringBuilder();
                        let types = entry.getValue().mAnonymousImpls;
                        let type = types.get(++index);
                        let docs = undefined;
                        let fields = undefined;
                        let methods = undefined;
                        builder.append(CodeWriter.BEGIN_BRACE).append(CodeWriter.NEW_LINE);
                        if (!Objects_js_1.Objects.isNull(type)) {
                            docs = type.mDocs;
                            fields = type.mFields;
                            methods = type.mMethods;
                            this.addIndent();
                            if (!Objects_js_1.Objects.isNull(docs)) {
                                for (let entry of docs.entries()) {
                                    this.insertIndentation(builder);
                                    builder.append("//").append(entry.getValue());
                                    if (!entry.isLastData())
                                        builder.append(CodeWriter.NEW_LINE);
                                }
                            }
                            builder.append(CodeWriter.NEW_LINE);
                            if (!Objects_js_1.Objects.isNull(fields)) {
                                for (let entry of fields.entries()) {
                                    let field = entry.getValue();
                                    let fieldName = field.mName;
                                    let fieldValue = field.mValue;
                                    this.insertIndentation(builder);
                                    if ((typeof fieldValue) == "object") {
                                        if (fieldValue.constructor.name == "Array") {
                                            builder.append(fieldName)
                                                .append(":")
                                                .append(CodeWriter.BEGIN_BRACKET);
                                            let list = Arrays_js_1.Arrays.asList(fieldValue);
                                            for (let entry of list.entries())
                                                this.emitFieldAnonymousImpls(undefined, entry.getValue(), (!entry.isLastData()), builder);
                                            builder.append(CodeWriter.NEW_LINE);
                                            this.insertIndentation(builder);
                                            builder.append(CodeWriter.END_BRACKET);
                                        }
                                        else {
                                            builder.append(fieldName)
                                                .append(":")
                                                .append(CodeWriter.BEGIN_BRACE);
                                            let map = LinkedMap_js_1.LinkedMap.fromObject(fieldValue);
                                            for (let entry of map.entries())
                                                this.emitFieldAnonymousImpls(entry.getKey(), entry.getValue(), (!entry.isLastData()), builder);
                                            builder.append(CodeWriter.NEW_LINE);
                                            this.insertIndentation(builder);
                                            builder.append(CodeWriter.END_BRACE);
                                        }
                                    }
                                    else if (fieldValue == TSField_js_1.TSField.UNDEFINED) {
                                        if (fieldName != undefined)
                                            builder.append(fieldName).append(":");
                                        builder.append(undefined);
                                    }
                                    else if (fieldValue.constructor.name == "String") {
                                        if (fieldName != undefined)
                                            builder.append(fieldName).append(":");
                                        builder.append(`\`${fieldValue}\``);
                                    }
                                    else {
                                        if (fieldName != undefined)
                                            builder.append(fieldName).append(":");
                                        builder.append(fieldValue);
                                    }
                                    if (!entry.isLastData())
                                        builder.append(CodeWriter.NEW_LINE).append(CodeWriter.COMMA);
                                }
                            }
                            if (!Objects_js_1.Objects.isNull(methods)) {
                                if (!methods.isEmpty())
                                    builder.append(CodeWriter.COMMA);
                            }
                            builder.append(CodeWriter.NEW_LINE);
                            if (!Objects_js_1.Objects.isNull(methods)) {
                                for (let entry of methods.entries()) {
                                    this.insertIndentation(builder);
                                    let method = entry.getValue();
                                    let name = method.mName;
                                    builder.append(name).append(":");
                                    this.emitParameterValue(method.mParameters, builder);
                                    builder.append(" =>").append(CodeWriter.BEGIN_BRACE);
                                    this.emitCodeBlock(method.mCodeBlocks, builder);
                                    if (!method.mCodeBlocks.isEmpty()) {
                                        builder.append(CodeWriter.NEW_LINE);
                                        this.removeIndent();
                                        this.insertIndentation(builder);
                                    }
                                    builder.append(CodeWriter.END_BRACE);
                                }
                            }
                            builder.append(CodeWriter.NEW_LINE);
                            this.removeIndent();
                            this.insertIndentation(builder);
                        }
                        builder.append(CodeWriter.END_BRACE);
                        code = code.replace("{$I}", builder.toString());
                    }
                    switch (code) {
                        case CodeWriter.BEGIN_BRACE:
                            builder.append(code);
                            this.addIndent();
                            break;
                        case CodeWriter.END_BRACE:
                        case CodeWriter.END_BRACE_SEMICOLON:
                            builder.append(CodeWriter.NEW_LINE);
                            this.removeIndent();
                            this.insertIndentation(builder);
                            builder.append((code == CodeWriter.END_BRACE_SEMICOLON ? `${CodeWriter.END_BRACE}${CodeWriter.SEMICOLON}` : code));
                            if (codes.isLastData() && !entry.isLastData()) {
                                builder.append(CodeWriter.NEW_LINE);
                                this.insertIndentation(builder);
                            }
                            break;
                        default:
                            if (!codes.isFirstData()) {
                                builder.append(CodeWriter.NEW_LINE);
                                this.insertIndentation(builder);
                            }
                            builder.append(code);
                            break;
                    }
                }
            }
        }
    }
    emitFieldAnonymousImpls(name, value, comma, builder) {
        builder.append(CodeWriter.NEW_LINE);
        this.addIndent();
        this.insertIndentation(builder);
        if ((typeof value) == "object") {
            if (value.constructor.name == "Array") {
                builder.append(name)
                    .append(":")
                    .append(CodeWriter.BEGIN_BRACKET);
                let list = Arrays_js_1.Arrays.asList(value);
                for (let entry of list.entries())
                    this.emitFieldAnonymousImpls(undefined, entry.getValue(), (!entry.isLastData()), builder);
                builder.append(CodeWriter.NEW_LINE);
                this.insertIndentation(builder);
                builder.append(CodeWriter.END_BRACKET);
            }
            else {
                builder.append(name)
                    .append(":")
                    .append(CodeWriter.BEGIN_BRACE);
                let map = LinkedMap_js_1.LinkedMap.fromObject(value);
                for (let entry of map.entries())
                    this.emitFieldAnonymousImpls(entry.getKey(), entry.getValue(), (!entry.isLastData()), builder);
                builder.append(CodeWriter.NEW_LINE);
                this.insertIndentation(builder);
                builder.append(CodeWriter.END_BRACE);
            }
        }
        else if (value.constructor.name == "String") {
            if (name != undefined)
                builder.append(name).append(":");
            builder.append(`\`${value}\``);
        }
        else {
            if (name != undefined)
                builder.append(name).append(":");
            builder.append(value);
        }
        if (comma)
            builder.append(comma ? CodeWriter.COMMA : "");
        this.removeIndent();
    }
    getCount() {
        return this.mIndents;
    }
    addIndent() {
        this.mIndents += 1;
    }
    removeIndent() {
        this.mIndents -= 1;
    }
    removeAllmIndents() {
        this.mIndents = 0;
    }
    insertIndentation(builder) {
        let numIndent = this.mIndents;
        if (Objects_js_1.Objects.isNull(builder))
            for (let i = 0; i < numIndent; i++)
                this.mAppendable.append(CodeWriter.TAB);
        else
            for (let i = 0; i < numIndent; i++)
                builder.append(CodeWriter.TAB);
    }
}
exports.CodeWriter = CodeWriter;
CodeWriter.BEGIN_BRACE = '{';
CodeWriter.END_BRACE = '}';
CodeWriter.BEGIN_BRACKET = "[";
CodeWriter.END_BRACKET = "]";
CodeWriter.SEMICOLON = ';';
CodeWriter.NEW_LINE = '\n';
CodeWriter.TAB = '\t';
CodeWriter.COMMA = ",";
CodeWriter.END_BRACE_SEMICOLON = "msay2.tspoet:END_BRACE_SEMICOLON";
//# sourceMappingURL=CodeWriter.js.map